﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi001.Domain;
using WebApi001.Domain.Entity;

namespace WebApi0001.Domain
{
    public class DbInitializeHelper
    {
        public static void Initilizer()
        {
            using (var db = new Admin4000DbContext())
            {
               var dbExist= db.Database.EnsureCreated();

                //检测是否包含任何实体
                var tempBrand = db.Brands.Any();


                if (!dbExist)
                {
                    var brand = new Brand
                    {
                        BrandName = "Apple",
                        Description = "美国的一个手机品牌",
                    };


                    db.Brands.Add(brand);
                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Iphone X 银色",
                        ShortDesc ="简介",
                        FullDesc ="详情",
                        BrandId = brand.Id

                    },new Product
                    {
                        ProductName = "Iphone X 土豪金色",
                        ShortDesc ="简介",
                        FullDesc ="详情",
                        BrandId = brand.Id

                    }
                    });
                    db.SaveChanges();
                }


                
               
            }
        } 
    }
}
